package userConsole.service;

import org.json.JSONException;
import org.json.JSONObject;
import userConsole.jdbc.BaseJDBC;
import userConsole.jdbc.UserJDBC;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author Godv
 * @version 1.0
 */
public class CheckUsernameService {
    public JSONObject checkUsername(String username) throws SQLException, JSONException {
        Connection connection = BaseJDBC.createConnection();
        UserJDBC userJDBC = new UserJDBC();
        int count = userJDBC.checkUsername(connection, username);
        JSONObject jsonObject = new JSONObject();
        if(count == 0) {   // 代表用户名不存在，允许用户注册
            jsonObject.put("code", 200);
            jsonObject.put("msg", "恭喜您！此用户名可以注册");
        }
        else {
            jsonObject.put("code", 506);
            jsonObject.put("msg", "对不起，此用户名已存在");
        }
        String s = "";
        s.equals(null);
        return jsonObject;
    }
}
